<?php
error_reporting(0);
session_start();
include_once '../comm/config.php';
include_once '../comm/checkpostandget.php';
include_once 'check.php';
include_once 'page.class.php';
include_once '../comm/wjt.php';

function tgyj($top_name,$down_name){
	global $BIAOTOU;
    $sql="SELECT sum(je) as tgyj FROM `".$BIAOTOU."mingxi` WHERE `ddusername`='$top_name' and `memo` like '交易人$down_name%'";
	$query=mysql_query($sql);
	$row=mysql_fetch_array($query);
	return $row[0]?$row[0]:0;
}

function buy_num($uid){
	global $BIAOTOU;
    $sql="select count(Id) from ".$BIAOTOU."tradelist where outer_code='".$uid."' and checked=2";
	$query=mysql_query($sql);
	$row=mysql_fetch_array($query);
	$tao_num=$row[0]?$row[0]:0;
	
	$sql="select count(id) from ".$BIAOTOU."mall_order where u_id='".$uid."' and stat_desc='核对有效'";
	$query=mysql_query($sql);
	$row=mysql_fetch_array($query);
	$mall_num=$row[0]?$row[0]:0;
	
	return $tao_num+$mall_num;
}

$pagesize=10;
$page = !($_GET['page'])?'1':intval($_GET['page']);
$page2=($page-1)*$pagesize;
$q = "SELECT * FROM ".$BIAOTOU."user where tjr='".$_SESSION["dduserid"]."'";
$rsin01 = mysql_query($q);
$total=mysql_num_rows($rsin01);
$q = "SELECT * FROM ".$BIAOTOU."user where tjr='".$_SESSION["dduserid"]."' order by loginnum desc limit ".$page2.",".$pagesize;
$rs = mysql_query($q);
while($row=mysql_fetch_array($rs)){
	$arr[$i]=$row;
	$arr[$i]['tgyj']=tgyj($_SESSION['duoduouser'],$row['ddusername']);
	$i++;
}

$tag="center";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<title>推广赚钱 - 用户中心</title>
<link href="../template/<?=MOBAN?>/css/style.css" rel="stylesheet" type="text/css" />
<link  href="../template/<?=MOBAN?>/css/layout.css" rel="stylesheet" type="text/css" />
<link  href="../template/<?=MOBAN?>/css/comm.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../js/jquery.js"></script> 
<style type="text/css">
/*分页*/
.megas512 {height:38px;width:770px;float:left;margin-top:15px}
.megas512 a{height:36px;min-width:36px;width:auto!important;width:36px;display:inline-block;background:#efefef;line-height:38px;font-size:16px;font-weight:bold;margin-left:4px;text-align:center}
.megas512 a:hover{height:36px;min-width:36px;width:auto!important;width:36px;display:inline-block;background:#cc0000;line-height:38px;font-size:16px;font-weight:bold;margin-left:4px;text-align:center;color:#FFF;text-decoration:none}
.megas512 A:active{height:36px;min-width:36px;width:auto!important;width:36px;display:inline-block;line-height:38px;font-size:16px;font-weight:bold;margin-left:4px;}
.megas512 SPAN.current{height:36px;min-width:36px;width:auto!important;width:36px;display:inline-block;line-height:38px;font-size:16px;font-weight:bold;margin-left:4px;text-align:center;color:#cc0000;text-decoration:none}
.megas512 SPAN.disabled{height:36px;min-width:36px;width:auto!important;width:36px;display:inline-block;line-height:38px;font-size:16px;font-weight:bold;margin-left:4px;text-align:center;color:#cc0000;text-decoration:none}

.layout_body table td{border-bottom:#f1f1f1 solid 1px}
</style>
</head>

<?php
$modtag="center";
include("../template/".MOBAN."/header_user.tpl.php");
?>


<div class='layout_body'>

  <div class="uInfoTop">
     <div class="break"><a href="javascript:void();" onclick="javascript:window.history.back();"><img src="../template/<?=MOBAN?>/images/back.gif" width="29" height="30" border="0" /></a></div>
     <div class="username usernamefont"><?=$_SESSION["duoduouser"]?></div>
     <div class="userstate"><a class="ustatefont" href="exit.php">退出</a></div>
  </div>
  <div class="usertopline"></div>

<div class="clears"></div>
<div class="CreatL">
<ul>
  <li><a href="tradelist.php?act=taobao">返米管理</a></li>
  <li class="UserSel"><a href="tuiguang_url.php"> 我要推广赚米</a></li>
  <li><a href="baobei.php">我的晒吧</a></li>
  <li><a href="huan.php">我的兑换</a></li>
</ul>
</div>
<div class="CreatR">
<ul class="babydetail MarginB10">
    <li><a href="tuiguang_url.php">我要推广</a></li>
    <li class="active"><a href="tuiguang.php">我推广的好友</a></li>
    </ul>
    <div class="clears"></div>
    
   <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr>
    <td width="12%" height="35" align="center" bgcolor="#f5f5f5">用户名</td>
    <td width="25%" valign="center" bgcolor="#f5f5f5">&nbsp;</td>
    <td width="16%" align="center" bgcolor="#f5f5f5">已获佣金/米</td>
    <td width="18%" align="center" bgcolor="#f5f5f5">登录次数</td>
    <td width="11%" align="center" bgcolor="#f5f5f5">购买次数</td>
    <td width="18%" align="center" bgcolor="#f5f5f5">注册时间</td>
  </tr>
  <?php foreach($arr as $arr){?>
  <tr>
    <td width="12%" height="80" align="center"><img src="../template/<?=MOBAN?>/images/tguser.gif" width="64" height="63" class="TGuser"/></td>
    <td width="25%" align="left" valign="top"><p><?=$arr['ddusername']?></p></td>
    <td width="16%" align="center"><span class="ColorRed Font16"><strong><?=round($arr['tgyj'],2)*100?></strong></span></td>
    <td width="18%" align="center"><?=$arr['loginnum']?></td>
    <td width="11%" align="center"><?=buy_num($arr['Id'])?></td>
    <td width="18%" align="center"><?=$arr['regtime']?></td>
  </tr>
  <?php }?>

   </table>
	<div class="megas512"><?php pageft($total,$pagesize,1,1,0,10,"tuiguang.php?keyword=".$keyword);	echo $pagenav;?></div>
    </div>
    <div class="clears"></div>
</div>
<div class="clears"></div>
</div>

<div class="lineclear" style="margin-top:50px"></div>
<?php
include("../template/".MOBAN."/footer.tpl.php");
?>
</body>
</html>
